﻿#ifndef TK_NET_TCP_CLIENT_H
#define TK_NET_TCP_CLIENT_H
#include <QObject>

#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/udp.hpp>



#include "tk_data_type.h"
#include "tk_mutex.h"
//#include "tk_net.h"

namespace tk{
namespace io{

using boost::asio::socket_base;
using boost::asio::ip::tcp;
using boost::asio::ip::address_v4;

//============================================================
class client;
class TkNetTcpClient
{
public:
    TkNetTcpClient();
    ~TkNetTcpClient();

    tk_bool Init(QString remote_ip, tk_uint16 remote_port,tk_uint16 local_port,tk_int32 over_time_ms = 1000);
    void Exit();
public:
    tk_bool Send(QByteArray &data);
    tk_bool Recv(QByteArray &data,tk_int32 timeout_ms);
private:
    void CloseAll();
private:
    boost::asio::io_context * m_p_io_context;
	tcp::socket * m_p_socket;

    TkMutex m_mutex_recv;
	TkMutex m_mutex_send;

	tcp::endpoint m_listen_endpoint;
	tcp::endpoint m_remote_endpoint;

    QString m_remote_ip;
    tk_uint16 m_remote_port;

    tk_uint16 m_local_port;
    client * m_p_client;
	
	boost::array<tk_uint8, 10000> m_recv_buf;
};


}//namespace io
}//namespace tk


#endif // TK_NET_TCP_CLIENT_H
